package com.live.stamp.base.validation;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.container.core.common.BusinessException;

/**
 * 正整数验证处理器
 */
public class PositiveIntegerHandle extends ParamHandler {
    private static final Logger logger = LoggerFactory.getLogger(PositiveIntegerHandle.class);

    @Override
    protected ValidationEnum getParamHandleType() {
        return ValidationEnum.POSITIVE_INTEGER;
    }

    @Override
    protected void echo(String paramName, Object param) {
        Integer p = (Integer)param;
        if(p == null){
            logger.error("PositiveIntegerHandle class -> param is null!");
            throw new BusinessException("数字不存在");
        }
        if(p < 1){
            logger.error("PositiveIntegerHandle class -> PositiveInteger:{} is error!", p);
            throw new BusinessException("数字不是正整数");
        }
    }
}
